$(document).ready(function() {
    /*查询已同意的立项申请*/
    findAgreedProject();
    applyProject()
    edit()
});
function findAgreedProject() {
    $('#dataTable').dataTable({
        "bDeferRender":true,
        "sAjaxDataProp":"data.projectList",
        "sAjaxSource":"http://localhost:8080/finishProject/findAgreedProject?stuInfoId="+2,
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function( oSettings ) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumnDefs": [
            {
                "mDataProp": null,
                "sDefaultContent": "<a href='#'><span  class='label label-danger mr10 mb10'>结项申请</span></a>",
                "aTargets": [-1]
            }
        ],
        "aoColumns": [
            {"mDataProp":"projectId"},
            {"mDataProp":"stuNum"},
            {"mDataProp":"stuName"},
            {"mDataProp":"termYear"},
            {"mDataProp":"termNum"},
            {"mDataProp":"projectName"},
            {"mDataProp":"projectContent"},
            {"mDataProp":"projectStartDate"},
            {"mDataProp":"projectEndtDate"},
            {"mDataProp":"projectContactPeople"},
            {"mDataProp":"projectPhonenum"},
            {"mDataProp":"projectPlatform"},
            {"mDataProp":"projectState",
                "mRender": function(data) {
                   /* var value = "<a href='#'><span id='re-apply' class='label label-danger mr10 mb10'>未通过</span></a>";*/
                    if (data==1){
                        value = "<a href='#'><span  class='label label-danger mr10 mb10' id='applyFinish'>结项申请</span></a>";
                    }if (data==3){
                        value = "<span  class='badge badge-info mr10 mb10'>已通过</span>";
                    }
                    if (data==4){
                        value = "<a href='#'><span id='edit-btn' class='badge badge-warning mr10 mb10'>未通过</span></a>";
                    }
                    if (data==5){
                        value = "<span id='edit-btn' class='label label-yellow mr10 mb10'>审核中</span>";
                    }
                    return value;
                }
            }
        ],

    })
}

function applyProject(){
    $(document).on('click', '#applyFinish', function () {
        var projectId = $(this).parents("tr").children(0).eq(0).text();
        var stuNum = $(this).parents("tr").children(0).eq(1).text();
        var stuName = $(this).parents("tr").children(0).eq(2).text();
        var termYear = $(this).parents("tr").children(0).eq(3).text();
        var termNum = $(this).parents("tr").children(0).eq(4).text();
        var projectName = $(this).parents("tr").children(0).eq(5).text();
        var projectPlatform = $(this).parents("tr").children(0).eq(11).text();
        var projectContactPeople = $(this).parents("tr").children(0).eq(9).text();
        var projectPhonenum = $(this).parents("tr").children(0).eq(10).text();
        var projectStartDate = $(this).parents("tr").children(0).eq(7).text();
        var projectEndtDate = $(this).parents("tr").children(0).eq(8).text();
      /*  alert("-projectId-" + projectId + "-stuNum-" + stuNum + "-stuName-" + stuName+ "-termYear-" + termYear +
            "-termNum-" + termNum+ "-projectName-" + projectName + "-projectPlatform-" + projectPlatform+ "-projectStartDate-" + projectStartDate +
            "-projectContactPeople-" + projectContactPeople+ "-projectPhonenum-" + projectPhonenum )*/
        location.href='applyFinishProject.html?projectId='+projectId+
            '&stuNum='+encodeURI(encodeURI(stuNum))+
            '&stuName='+encodeURI(encodeURI(stuName)) +
            '&termYear=' + encodeURI(encodeURI(termYear))+
            '&termNum=' + encodeURI(encodeURI(termNum))+
            '&projectName=' + encodeURI(encodeURI(projectName))+
            '&projectPlatform=' + encodeURI(encodeURI(projectPlatform))+
            '&projectContactPeople=' + encodeURI(encodeURI(projectContactPeople))+
            '&projectPhonenum=' + encodeURI(encodeURI(projectPhonenum))+
            '&projectEndtDate=' + encodeURI(encodeURI(projectEndtDate))+
            '&projectStartDate=' + encodeURI(encodeURI(projectStartDate));
    })
}

function edit(){
    $(document).on('click', '#edit-btn', function () {
        var projectId = $(this).parents("tr").children(0).eq(0).text();
        var stuNum = $(this).parents("tr").children(0).eq(1).text();
        var stuName = $(this).parents("tr").children(0).eq(2).text();
        var termYear = $(this).parents("tr").children(0).eq(3).text();
        var termNum = $(this).parents("tr").children(0).eq(4).text();
        var projectName = $(this).parents("tr").children(0).eq(5).text();
        var projectPlatform = $(this).parents("tr").children(0).eq(11).text();
        var projectContactPeople = $(this).parents("tr").children(0).eq(9).text();
        var projectPhonenum = $(this).parents("tr").children(0).eq(10).text();
        var projectStartDate = $(this).parents("tr").children(0).eq(7).text();
        var projectEndtDate = $(this).parents("tr").children(0).eq(8).text();
        /*  alert("-projectId-" + projectId + "-stuNum-" + stuNum + "-stuName-" + stuName+ "-termYear-" + termYear +
              "-termNum-" + termNum+ "-projectName-" + projectName + "-projectPlatform-" + projectPlatform+ "-projectStartDate-" + projectStartDate +
              "-projectContactPeople-" + projectContactPeople+ "-projectPhonenum-" + projectPhonenum )*/
        location.href='applyFinishProject.html?projectId='+projectId+
            '&stuNum='+encodeURI(encodeURI(stuNum))+
            '&stuName='+encodeURI(encodeURI(stuName)) +
            '&termYear=' + encodeURI(encodeURI(termYear))+
            '&termNum=' + encodeURI(encodeURI(termNum))+
            '&projectName=' + encodeURI(encodeURI(projectName))+
            '&projectPlatform=' + encodeURI(encodeURI(projectPlatform))+
            '&projectContactPeople=' + encodeURI(encodeURI(projectContactPeople))+
            '&projectPhonenum=' + encodeURI(encodeURI(projectPhonenum))+
            '&projectEndtDate=' + encodeURI(encodeURI(projectEndtDate))+
            '&projectStartDate=' + encodeURI(encodeURI(projectStartDate));
    })
}